home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 3_9.lha / 3_9 / 3_9a.c next >
C/C++ Source or Header  |  1993-08-08  |  472b  |  20 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / concatenate the two strings s1 and s2 into
  6. / a new string allocated on the free store
  7. include <string.h>
  8. har *cat(const char *s1, const char *s2)
  9.  
  10.    if (!s1 || !s2)
  11. return 0;
  12.  
  13.    int length1 = strlen(s1);
  14.    char *ret = new char [ length1 + strlen(s2) + 1 ];
  15.  
  16.    strcpy(ret, s1);
  17.    strcpy(ret + length1, s2);
  18.    return ret;
  19.  
  20.